<%@ page language="java"  pageEncoding="utf-8"%>
<%@page import="java.nio.charset.Charset"%>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<%@ page import=" java.util.Vector,com.ejoysoft.wlanyz.business.WarnAppear,com.ejoysoft.common.Constants,com.ejoysoft.common.exception.NoRightException" %>
<%@ include file="../include/jsp/head.jsp"%>
<%
if(!globa.userSession.hasRight("10035"))
      throw new NoRightException("用户不具备操作该功能模块的权限，请与系统管理员联系！");
%>
<%
    //初始化
    WarnAppear  warn=null;
    WarnAppear obj=new WarnAppear(globa);
    //查询条件
    String  strCity=ParamUtil.getString(request,"strCity","").trim();
    String  strEndTime=ParamUtil.getString(request,"strEndTime","").trim();
    String  strStartTime=ParamUtil.getString(request,"strStartTime","").trim();
    String  checkedFlag = ParamUtil.getString(request,"checkedFlag","").trim();
    String  strIndicatorName=ParamUtil.getString(request,"strIndicatorName","").trim();
    String exportFlag = ParamUtil.getString(request,"exportFlag","");
	String exportContent = ParamUtil.getString(request,"exportContent","");
		//当前页
    int intCurPage = Integer.parseInt(ParamUtil.getString(request,"strCurPage","1"));
	String tWhere=" WHERE 1=1 and a.strnettype =  '"+checkedFlag+"'";
    if(!strCity.equals("")){
     tWhere += " and a.strCity LIKE '%"+ strCity +"%' " ;
    }
	//记录总数
	int intAllCount=obj.getCount(tWhere,strStartTime,strEndTime);	

	//每页记录数
	String strPageSize = ParamUtil.getString(request,"strPageSize","15");
    int intPageSize;
    if(strPageSize.equals("所有"))intPageSize = intAllCount;
      else  intPageSize = Integer.parseInt(strPageSize);
	//共有页数
 	int intPageCount=(intAllCount-1)/intPageSize+1;
	// 循环显示一页内的记录 开始序号
	int intStartNum=(intCurPage-1)*intPageSize+1;
	//结束序号
	int intEndNum=intCurPage*intPageSize;   
	//获取到当前页面的记录集
	Vector<WarnAppear> vctObj=obj.list(tWhere,intStartNum,intPageSize,strStartTime,strEndTime);
	//获取当前页的记录条数
	int intVct=(vctObj!=null&&vctObj.size()>0?vctObj.size():0);
    
	if(exportFlag.equals("exportResult"))
	{
		if(exportContent.equals("allPage"))
		{
			vctObj=obj.list(tWhere,0,0,strStartTime,strEndTime);
		}
   	   	StringBuffer sb = new StringBuffer("<html><body><table border='1'>");
   	    sb.append("<tr><td>地市</td><td>区县</td><td>任务名称</td><td>AP名称</td><td>MAC地址</td><td>小区区号</td><td>小区ID</td><td>指标名</td><td>指标值</td></tr>");
	    if (vctObj.size() != 0)
	    {  
	        for (int i = 0; i < vctObj.size(); i++)
		    {
		    System.out.println(vctObj.get(i).getStrCity()+vctObj.get(i).getStrTown());
		       sb.append("<tr><td> ");
		       sb.append((vctObj.get(i).getStrCity()==null?"":vctObj.get(i).getStrCity()));
		       sb.append("</td><td> ");
		         sb.append((vctObj.get(i).getStrTown()==null?"":vctObj.get(i).getStrTown()));
		          sb.append("</td><td> ");
		         sb.append((vctObj.get(i).getStrTaskName()==null?"":vctObj.get(i).getStrTaskName()));
		          sb.append("</td><td> ");
		         sb.append((vctObj.get(i).getStrApName()==null?"":vctObj.get(i).getStrApName()));
		          sb.append("</td><td> ");
		        sb.append((vctObj.get(i).getStrMac()==null?"":vctObj.get(i).getStrMac()));
		         sb.append("</td><td> ");
		         sb.append((vctObj.get(i).getStrCommunityId()==null?"":vctObj.get(i).getStrCommunityId()) );
		          sb.append( "</td><td> ");
		        sb.append((vctObj.get(i).getLac(vctObj.get(i).getStrCommunityId())==null?"":vctObj.get(i).getLac(vctObj.get(i).getStrCommunityId())));
		         sb.append("</td><td> ");
		         sb.append((vctObj.get(i).getStrIndicatorName()==null?"":vctObj.get(i).getStrIndicatorName()));
		          sb.append("</td><td> ");
		         sb.append(vctObj.get(i).getIntIndicatorValue());
		          sb.append("</td></tr>"); 
		    }
		    if(vctObj.size()==1){  	 
		        sb.append("<tr><td> </td><td></td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td><td> </td></tr>");
			 }
		    
	    }
   	   	sb.append("</table></body></html>");
   	   	System.out.println(sb);
	    String strFileName = "预警呈现表.xls";//自定义xls文件的文件名
	    response.setCharacterEncoding("utf-8");
	    response.setContentType("APPLICATION/*;charset=utf-8");
	    response.setHeader( "Content-Disposition", "attachment;filename="  + new String( strFileName.getBytes("gbk"), "ISO8859-1"));
	    out.clearBuffer(); 
	    out = pageContext.pushBody();
	    ServletOutputStream output = response.getOutputStream();
	    System.out.println(sb.toString().getBytes("utf-8"));
	    output.write(sb.toString().getBytes("utf-8"));
	  //out.clearBuffer(); 
	//  WarnAppear.shareMethodForExport(sb,strFileName,response,out,pageContext);
 
	} 
%>
<%@ include file="../include/jsp/footer.jsp"%>
